home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14080 < prev    next >
Encoding:
Text File  |  1996-08-05  |  995 b   |  35 lines

  1. Path: lyra.csx.cam.ac.uk!news
  2. From: gdr11@cl.cam.ac.uk (Gareth Rees)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: About union
  5. Date: 11 Apr 1996 20:39:12 +0100
  6. Organization: Cambridge University Computer Lab
  7. Message-ID: <yxslok2o8in.fsf@stint.cl.cam.ac.uk>
  8. References: <4kfj5g$24n@dewey.csun.edu>
  9. NNTP-Posting-Host: stint.cl.cam.ac.uk
  10. In-reply-to: kc44097@csun.edu's message of 10 Apr 1996 06:06:40 GMT
  11. X-Newsreader: Gnus v5.0.15
  12.  
  13. chen <kc44097@csun.edu> wrote:
  14. > I read the program below from a book and do not know how it works.
  15. > Can anyone give me some advice ?
  16.  
  17. The code you posted does not work; it invokes implementation-dependent
  18. behaviour.
  19.  
  20. > union {
  21. >   int   integer;
  22. >   float floating;
  23. > } myUnion;
  24. > main() {
  25. [etc]
  26. >   (void) printf("The value of \"magic\" is %f\n\n", myUnion.integer);
  27.  
  28. This causes `printf' to attempt to interpret an argument passed as `int'
  29. as though it were a `float', which is illegal (the argument types must
  30. match the conversion specifications).
  31.  
  32. -- 
  33. Gareth Rees
  34.